package no.sachmuld.methodcombination.api.adapter;

import no.sachmuld.methodcombination.impl.AbstractMethodInvocation;
import no.sachmuld.methodcombination.api.BehaviourChain;
import no.sachmuld.methodcombination.api.MethodInvocation;

/**
 *
 */
public abstract class Default<B, R> {

    private BehaviourChain<B> chain;

    public Default(BehaviourChain<B> chain) {
        this.chain = chain;
    }

    public R execute() {

        return new AbstractMethodInvocation<B, R>(chain.bottomUp(), null, null, null) {
            @Override
            protected R executeBehaviour(B behaviour) {
                return Default.this.executeBehaviour(behaviour, this);
            }
        }.execute();

    }

    protected abstract R executeBehaviour(B behaviour, MethodInvocation<R> methodInvocation);

}
